package com.bee.shepherd.service.security;

import com.google.common.base.Preconditions;
import com.qunar.finance.nbdata.security.core.api.bean.NbKeyType;
import com.qunar.finance.nbdata.security.core.api.service.NbInfoDecryptClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * NB 解密服务
 */
//@Service
public class DecryptDataServiceImpl implements IDecryptDataService {

//    @Resource
    private NbInfoDecryptClient nbInfoDecryptClient;

    @Override
    public String decryptPhone(String input) {
        return decrypt(input, NbKeyType.phone);
    }

    @Override
    public String decryptMail(String input) {
        return decrypt(input, NbKeyType.mail);
    }

    @Override
    public String decryptBankNo(String input) {
        return decrypt(input, NbKeyType.bankNo);
    }

    @Override
    public String decryptPersonalId(String input) {
        return decrypt(input, NbKeyType.personal_id);
    }

    @Override
    public String decryptPassport(String input) {
        return decrypt(input, NbKeyType.passport);
    }

    private String decrypt(String input,NbKeyType nbKeyType) {
        String result = input;
        if (StringUtils.isNotBlank(input)) {
            result = nbInfoDecryptClient.decrypt(nbKeyType, input);
        }
        Preconditions.checkNotNull(result, "解密失败,结果为null,原串:" + input);
        return result;
    }
}
